package com.songshuai.pangu.api.backcontroller;

import com.songshuai.pangu.api.service.PhpSopService;
import com.songshuai.webapi.baseapi.dto.feign.response.phpsop.SopDto;
import com.songshuai.webapi.baseapi.dto.feign.response.phpsop.SopTypeDto;
import com.songshuai.webapi.baseapi.dto.pangu.request.phpsop.PhpSopReqDto;
import com.songshuai.webapi.baseapi.enumerations.ResultStatus;
import com.songshuai.webapi.baseapi.pojo.QueryPageRes;
import com.songshuai.webapi.baseapi.pojo.QueryResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author:wbl
 * @Date: 2019/3/20
 */
@Slf4j
@Api("活动中心")
@RestController
@RequestMapping("api/back/php/sop/")
public class PhpSopController {

    @Autowired
    private PhpSopService phpSopService;

    @ApiOperation(value = "查询php内容分类列表")
    @GetMapping("typeList")
    public QueryResponse<List<SopTypeDto>> getSopTypeListById(@RequestParam(value = "type", required = false) String type){
        try {
            List<SopTypeDto> sopTypeList = phpSopService.getSopTypeListById(type);
            if (null != sopTypeList){
                return QueryResponse.setResData(sopTypeList);
            }
        } catch (Exception ex) {
            log.error("/api/back/php/sop/typeList", ex);
            return new QueryResponse<>(ResultStatus.FAILOfficial.getErrorCode(),ex.getMessage());
        }
        return new QueryResponse<>(ResultStatus.ERROR_SEARCH_FAILED);
    }

    @ApiOperation(value = "查询php sop内容列表")
    @PostMapping("sopList")
    public QueryResponse<QueryPageRes<List<SopDto>>> getSopList(@RequestBody PhpSopReqDto phpSopReqDto){
        try {
            QueryPageRes<List<SopDto>> queryPageRes = phpSopService.getSopList(phpSopReqDto);
            if (null != queryPageRes){
                return QueryResponse.setResData(queryPageRes);
            }
        } catch (Exception ex) {
            log.error("/api/back/php/sop/sopList", ex);
            return new QueryResponse<>(ResultStatus.FAILOfficial.getErrorCode(),ex.getMessage());
        }
        return new QueryResponse<>(ResultStatus.ERROR_SEARCH_FAILED);
    }

    @ApiOperation(value = "查询php sop内容详情")
    @GetMapping("sopDetail")
    public QueryResponse<List<SopDto>> getSopDetail(@RequestParam(value = "id") String id){
        try {
            SopDto sopDto = phpSopService.getSopDetail(id);
            if (null != sopDto){
                return QueryResponse.setResData(sopDto);
            }
        } catch (Exception ex) {
            log.error("/api/back/php/sop/sopDetail", ex);
            return new QueryResponse<>(ResultStatus.FAILOfficial.getErrorCode(),ex.getMessage());
        }
        return new QueryResponse<>(ResultStatus.ERROR_SEARCH_FAILED);
    }
}
